package com.hq.learnmybatisplus.inject;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * sql 注入器 注入一个 deleteAll方法 如实现通用mapper的 insert selectById方法
 * 推荐 再自己写个通用mapper加入这个方法 int deleteAll()  继承BaseMapper  dao实现自己写的通用mapper(我这里是在UserDao里面加)
 * @see MySqlInject
 * @author hq
 */
public class SqlDeleteAllMethod extends AbstractMethod {

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        //需要执行的sql
        String sql = "delete from " + tableInfo.getTableName();
        //执行sql的名字
        String method = "deleteAll";
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return addDeleteMappedStatement(mapperClass,method,sqlSource);
    }
}
